<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Navbar;

/*
 * Dcat-admin - admin builder based on Laravel.
 * @author jqh <https://github.com/jqhph>
 *
 * Bootstraper for Admin.
 *
 * Here you can remove builtin form field:
 *
 * extend custom field:
 * Dcat\Admin\Form::extend('php', PHPEditor::class);
 * Dcat\Admin\Grid\Column::extend('php', PHPEditor::class);
 * Dcat\Admin\Grid\Filter::extend('php', PHPEditor::class);
 *
 * Or require js and css assets:
 * Admin::css('/packages/prettydocs/css/styles.css');
 * Admin::js('/packages/prettydocs/js/main.js');
 *
 */

Admin::navbar(function (Navbar $navbar) {
    $url = admin_url('im');
    $navbar->right(
        <<<HTML
    <a href="{$url}" target="_blank">客服</a>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>
    <a href="/horizon" target="_blank">队列监控</a>
HTML
    );
});

Grid::resolving(function ($grid) {
    $grid->withBorder();
    $grid->addTableClass(['table-text-center']);
    $grid->disableViewButton();
    $grid->model()->orderBy('created_at', 'desc')->orderBy('id', 'desc');
    $grid->fixColumns(0, true);
    $grid->export();
});
Form::resolving(function ($form) {
    $form->disableCreatingCheck();
    $form->disableDeleteButton();
    $form->disableListButton();
    $form->disableViewCheck();
    $form->disableResetButton();
    $form->disableEditingCheck();
    $form->disableViewButton();
});
$script = <<<'JS'
        $("#grid-table > tbody > tr").on("dblclick",function(event) {
           var obj = $(this).find(".feather.icon-edit-1");
           if (obj.attr('unique') == "true") {
               return
           }
           if (obj.length == 1) {
               obj.trigger("click")
               obj.attr('unique',true);
           }
        })


        var body = document;
        var dv = $('.table-main')[0];//大盒子
        //上一次的位置 scrollLeft
        if(dv){
                    var last_left = 0;
        var last_height = 0;
        dv.onmousedown = function (e) {
            dv.onmousemove = mousemove; //鼠标移动
            body.onmouseup = mouseup;   //鼠标按出
             e = e || window.event;
            //如果上次有记录

            if(last_left > 0 ){
                //就减掉上次的距离
                ox = last_left + e.clientX;
            }else{
                // ox = dv.scrollLeft - e.clientX;
                ox = e.clientX;
            }

             if(last_height > 0 ){
                //就减掉上次的距离
                ox2 = last_height + e.clientY;

            }else{
                // ox = dv.scrollLeft - e.clientX;
                ox2 = e.clientY;
            }

        };
        function mousemove(e) { //鼠标移动
            e = e || window.event;

            if(dv.scrollWidth-dv.scrollLeft!==dv.clientWidth){

              last_left = ox- e.clientX  ;

            }
            //  if(dv.scrollHeight-dv.scrollTop!==dv.clientHeight){
            //     if (dv.scrollTop > last_height ){
            //
            //           last_height = dv.scrollTop ;
            //      }else{
            //
            //   last_height = ox2- e.clientY  ;
            //  }
            //
            // }
            dv.scrollLeft = ox - e.clientX ;
             // if (dv.scrollTop < last_height ){
             //
             //     dv.scrollTop = ox2 - e.clientY ;
             // }


        }
        function mouseup(e) {
            dv.onmouseup = dv.onmousemove = null;
        }
        }

JS;
Admin::style(
    <<<'CSS'
   .table-responsive table tbody tr:hover{
        background: #f1dfcb !important;
   }
    #grid-table  {
        min-height: 500px !important;
   }
    footer {display: none}
*{
moz-user-select: -moz-none;
-moz-user-select: none;
-o-user-select:none;
-khtml-user-select:none;
-webkit-user-select:none;
-ms-user-select:none;
user-select:none;
}
CSS
);
Admin::script($script);
app('view')->prependNamespace('admin', resource_path('views/vendor/views'));
